function PageBackendSource(user, sd, options) {
  this._source = user;
  this._sd = sd;
  this._options = (options) ? options : null;
  
  this._gui = { navigation: document.getElementById('img1'),
                naviStatus: document.getElementById('td1'),
                name: document.getElementById('input1'),
                btnBack: document.getElementById('img2'),
                btnSave: document.getElementById('img3')
              };
  
  this._createElements();
};

PageBackendSource.prototype._createElements = function() {
  var a, tr, td, _self = this;
  
  this._gui.navigation.onclick = function() { location.href = '?p=pageasst&t=pagebackendsources&m1=a4&m2=b4'; };
  DOMUtils.removeChildElements(this._gui.naviStatus);
  var img = document.createElement('img');
  if (this._options.sid) {
    img.src = 'images/pageasst/pagebackendsource/editsource.png';
  } else {
    img.src = 'images/pageasst/pagebackendsource/addnewsource.png';
  }
  this._gui.naviStatus.appendChild(img);
  
  this._loadData();
};

PageBackendSource.prototype._loadData = function() {
  this._source = null;
  this._retrieveSource();
};

PageBackendSource.prototype._verifyData = function() {
  if (this._source) {
    this._updateElements();
  }
};

PageBackendSource.prototype._retrieveSource = function() {
  var _self = this;
  if (this._options.sid) {
    new RequestUtils()._read('source', null, 'd.oid = ' + this._options.sid, null, null, null, null, function(result, params) { _self._source = (result.data.length == 1) ? result.data[0] : null;
                                                                                                                                _self._verifyData.call(_self);
                                                                                                                              }, null);
  } else {
    this._source = Source.instance();
    this._verifyData();
  }
};

PageBackendSource.prototype._updateElements = function() {
  var table, tr, td, _self = this;

  this._gui.name.value = this._source.name;
  
  this._gui.name.onchange = function() { _self._source.name = this.value; };
  
  this._gui.btnSave.onclick = function() { new RequestUtils()._write('source', [_self._source], [], function() { location.href = '?p=pageasst&t=pagebackendsources&m1=a4&m2=b4'; }, null); };
  
  this._gui.btnBack.onclick = function() { location.href = '?p=pageasst&t=pagebackendsources&m1=a4&m2=b4'; };
};

